package com.lanou3g.dllo.baidumusic.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.main.MainActivity;

/**
 * Created by dllo on 16/6/17.
 */
public abstract class BaseActivity extends AppCompatActivity{

    public abstract int setLayout();

    public abstract void initView();

    public abstract void initData();

    protected FinishActivityReceiver finishActivityReceiver;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayout());
        initView();
        initData();

        finishActivityReceiver = new FinishActivityReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.lanou3g.dllo.baidumusic.finishActivity");
        registerReceiver(finishActivityReceiver,filter);
    }

    public void intentMainActivityAnimation() {

        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.in_animation,R.anim.out_animation);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.in_animation,R.anim.out_animation);
    }

    class FinishActivityReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(finishActivityReceiver);
    }
}
